package com.jvm.heap;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Demo {
    /**
     * -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
     * @param args
     */
    public static void main(String[] args) {
        List<JVMDEMO> l = new ArrayList<>();
        while (true){
            l.add(new JVMDEMO());
        }
    }
}

class JVMDEMO{
    List p = new ArrayList();

    public JVMDEMO() {
        Random random = new Random();
        int length = random.nextInt(1000);
        for(int i =0 ;i<length;i++){
            StringBuilder sb = new StringBuilder();
            int sub= random.nextInt(1000)+1000;
            for(int j= 0 ;j<sub;j++){
                Character c = (char) (random.nextInt(26)+'a');
//                Character c = (Character) (random.nextInt(26)+'a');//这样强制转化出错
                sb.append(c.toString());
                   }
            p.add(sb.toString());
        }
    }
}

